//
//  ViewController.m
//  Move
//
//  Created by iD Student on 7/10/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	ball.image = [UIImage imageNamed:@"Untitled-3.png"];
    [upAnimation addObject:[UIImage imageNamed:@"up1.png"]];
    [upAnimation addObject:[UIImage imageNamed:@"up2.png"]];
    [upAnimation addObject:[UIImage imageNamed:@"up3.png"]];
    [leftAnimation addObject:[UIImage imageNamed:@"left1.png"]];
    [leftAnimation addObject:[UIImage imageNamed:@"left2.png"]];
    [leftAnimation addObject:[UIImage imageNamed:@"left3.png"]];
    [rightAnimation addObject:[UIImage imageNamed:@"right1.png"]];
    [rightAnimation addObject:[UIImage imageNamed:@"right2.png"]];
    [rightAnimation addObject:[UIImage imageNamed:@"right3.png"]];
    [downAnimation addObject:[UIImage imageNamed:@"down1.png"]];
    [downAnimation addObject:[UIImage imageNamed:@"down2.png"]];
    [downAnimation addObject:[UIImage imageNamed:@"down3.png"]];
    gameTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(gameUpdate) userInfo: nil repeats:true];
}
-(IBAction)upPressed:(id)sender
{
    goingUp = true;
}
-(IBAction)downPressed:(id)sender
{
    goingDown=true;
}
-(IBAction)rightPressed:(id)sender
{
    goingRight=true;
}
-(IBAction)leftPressed:(id)sender
{
    goingLeft=true;
}
-(IBAction)buttonReleased:(id)sender
{
    goingDown=false;
    goingRight=false;
    goingLeft=false;
    goingUp=false;
}
-(void) gameUpdate
{
    if(goingUp == true)
    {
        CGPoint oldCenter = ball.center;
        ball.center = CGPointMake(oldCenter.x,oldCenter.y-3);
    }
    else if(goingDown == true)
    {
        CGPoint oldCenter = ball.center;
        ball.center = CGPointMake(oldCenter.x,oldCenter.y+3);
    }
    else if(goingRight == true)
    {
        CGPoint oldCenter = ball.center;
        ball.center = CGPointMake(oldCenter.x+3,oldCenter.y);
    }
    else if(goingLeft == true)
    {
        CGPoint oldCenter = ball.center;
        ball.center = CGPointMake(oldCenter.x-3,oldCenter.y);
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
